<script type="text/babel">
  export default {
    methods: {
      dispatchKeyEvent: function (keyEvent) {
        var handled = false
        var children = this.$children
        var len = children.length
        for (var i = 0; i < len; i++) {
          var child = children[i]
          if (!child.dispatchKeyEvent) {
            continue
          }
          handled = !!child.dispatchKeyEvent(keyEvent)
          if (handled) {
            break
          }
        }
        if (!handled) {
          if (keyEvent.action === 'action.down') {
            handled = this.onKeyDown(keyEvent)
          } else if (keyEvent.action === 'action.up') {
            handled = this.onKeyUp(keyEvent)
          }
        }
        return handled
      },
      onKeyDown: function (keyEvent) {
        return false
      },
      onKeyUp: function (keyEvent) {
        return false
      }
    }
  }
</script>